import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Window 2.12
import Qt.labs.platform 1.0

ApplicationWindow {
    id: window
    visible: false
    width: 400
    height: 600
    title: qsTr("数据中间件")

    SystemTrayIcon{

        visible: true
        iconSource: "qrc:/images/logo32.png"
        onActivated: {
            if(reason===2){
            window.show()
            window.raise()
            window.requestActivate()
            }
        }
        menu: Menu{
            MenuItem{
                text: qsTr("显示")
                onTriggered:{
                    window.show()
                    window.raise()
                    window.requestActivate()
                }
            }
            MenuItem{
                text: qsTr("退出程序")
                onTriggered: Qt.quit()
            }
        }
    }

    header: ToolBar {
        contentHeight: toolButton.implicitHeight

        ToolButton {
            id: toolButton
            text: stackView.depth > 1 ? "\u25C0" : "\u2630"
            font.pixelSize: Qt.application.font.pixelSize * 1.6
            onClicked: {
                if (stackView.depth > 1) {
                    stackView.pop()
                } else {
                    drawer.open()
                }
            }
        }

        Label {
            text: stackView.currentItem.title
            anchors.centerIn: parent
        }
    }

    Drawer {
        id: drawer
        width: window.width * 0.66
        height: window.height

        Column {
            anchors.fill: parent

            ItemDelegate {
                text: qsTr("设置")
                width: parent.width
                onClicked: {
                    stackView.push("Page1Form.ui.qml")
                    drawer.close()
                }
            }

        }
    }

    StackView {
        id: stackView
        initialItem: "HomeForm.ui.qml"
        anchors.fill: parent
    }
}
